# 索引和切片
# https://www.bilibili.com/video/BV19T4y127Z2/?p=4&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
import numpy as np

print("索引和切片")

a = np.arange(11) ** 2
print(a)
print(a[2])
print(a[-1])
print(a[2:6])
print(a[2:-1])
print(a[2:])
print(a[:-1])

# 每两个取一个
print(a[2:6:2])

# 倒着取
# step = -1
print(a[::-1])

# 索引
s = np.array([['Dave', 'Nick', 'Martin', 'Sarah'],
              ['98', '78', '65', '99'],
              ['96', '77', '89', '100']])
print(s)
print(s[0])
print(s[1])
print(s[2])
print(s[0, 1])
print(s[0:2, 2:3])
print(s[:, 2:4])
print("# 选择最后一行，所有列 #####################################")
print(s[-1, :])
print(s[-1, ...])
print(s[2, ...])
print(s[..., 3])